/*
* $Id: AddChangeInspectView.h 161 2010-10-03 23:45:28Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
#ifndef _ADD_CHANGE_INSPECT_VIEW_H_
#define _ADD_CHANGE_INSPECT_VIEW_H_

#include "AddChangeView.h"
#include "Components/Journal/InspectManager.h"

class CAddChangeInspectView : public CAddChangeView
{
protected:
	struct housing{
		int m_nId;
		std::tstring m_strName;
		housing() : m_nId(0){}
		housing(int nId, const std::tstring& strName)
			: m_nId(nId), m_strName(strName){}
		bool operator == (const housing& hive) const{
			return m_nId == hive.m_nId || m_strName == hive.m_strName && m_nId == hive.m_nId == 0;
		}
		bool operator < (const housing& hive) const{
			if(m_nId)
				return m_nId < hive.m_nId;
			else if(!m_nId && hive.m_nId)
				return true;
			return m_strName < hive.m_strName;
		}
	};
private:
	std::map<housing, int> m_aHousingUser;
	std::map<int, housing> m_aHousings;
	int m_nUserFields;
protected:
	int m_nIdRecord;
	int m_nCountHousing;
protected:
	virtual std::tstring GetHeaderString() = 0;
	virtual void GetHousings() = 0;
protected:
	void Init();
	void GetCurValue();
	void GetSaveData(CInspectManager::journal& jrn,
		std::vector<CInspectManager::inspect>& aInspect,
		std::map<std::tstring, std::tstring>& aUserField);
	void AddHousing(housing hive);
	void AddHousingFields();
protected:
	DECLARE_MESSAGE_MAP();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg LRESULT OnButtonClick(WPARAM wParam, LPARAM lParam);
public:
	CAddChangeInspectView(CState* pState);
	virtual ~CAddChangeInspectView();
};

class CAddInspectView : public CAddChangeInspectView
{
protected:
	DECLARE_MESSAGE_MAP();
	afx_msg void OnSaveInspect();
protected:
	virtual std::tstring GetHeaderString();
	virtual void GetHousings();
public:
	CAddInspectView(CState* pState);
	virtual ~CAddInspectView();
public:
	virtual void SetState();
	virtual bool IsViewState(State state);
};

class CChangeInspectView : public CAddChangeInspectView
{
protected:
	DECLARE_MESSAGE_MAP();
	afx_msg void OnSaveInspect();
protected:
	virtual std::tstring GetHeaderString();
	virtual void GetHousings();
	virtual void InitCurrentValue();
public:
	CChangeInspectView(CState* pState);
	virtual ~CChangeInspectView();
public:
	virtual void SetState();
	virtual bool IsViewState(State state);
};

#endif/*_ADD_CHANGE_INSPECT_VIEW_H_*/